package com.drojian.singleton.type2;

import org.junit.Test;

/**
 * 饿汉式(静态代码块)
 */
public class SingletonTest02 {
    @Test
    public void test01(){
        Singleton instance = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println(instance == instance2);
    }
}


class Singleton{
    private Singleton() {
    }
    static {
        instance = new Singleton();
    }
    private  static Singleton instance;
    public  static  Singleton getInstance(){
        return  instance;
    }
}